﻿Imports RWN.Common.Utility

Public Class Profile
	Inherits System.Web.UI.Page

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		If Not Page.IsPostBack Then
			If GlobalApp.Authen IsNot Nothing Then
				Dim info As Entity.OfficerInfoItem = BL.Officer.LoadProfile(GlobalApp.Authen.offcier_id)
				If info IsNot Nothing Then
					BindProfile(info)
					Me.ucEditAddress1.OfficerInfo = info
					Me.ucEditAddress1.initControlt()
				End If
			End If
		End If
	End Sub

	Public Sub BindProfile(ByVal profile As Entity.OfficerInfoItem)
		With Me
			.ltrAppId.Text = profile.officer_app_id
			.ltrAppTel.Text = profile.offcier_app_tel
			.ltrName.Text = profile.officer_firstname_tha
			.ltrLastname.Text = profile.officer_lastname_tha
			.ltrNameEng.Text = profile.officer_firstname_eng
			.ltrLastNameEng.Text = profile.officer_lastname_eng
			.ltrSex.Text = ConvertSex(profile.officer_sex)
            .ltrStatus.Text = ConvertMarriedStatus(profile.officer_married_status)
            .ltrCardType.Text = ConvertOfficerCardType(profile.officer_card_type)
            .ltrCardTypeDesc.Text = profile.officer_card_type_desc
			.ltrCardNo.Text = profile.officer_card_no

			Try
				.ltrCardExpiredDate.Text = profile.officer_card_expiredate.Value.AddYears(543).ToString("dd/MM/yyyy")
			Catch 
			End Try

			.ltrBrithDay.Text = profile.officer_birthdate.Value.AddYears(543).ToString("dd/MM/yyyy")
			.ltrAge.Text = Math.Round((DateTime.Today - profile.officer_birthdate.Value).TotalDays / 365).ToString("##")

			Try
				.ltrRegisDate.Text = profile.offcier_member_date.Value.AddYears(543).ToString("dd/MM/yyyy")
			Catch
			End Try

			.ltrSponser.Text = profile.officer_sponsor_name & " " & profile.officer_sponsor_surename

			Try
				.ltrExpriedDate.Text = profile.offcier_expird_date.Value.AddYears(543).ToString("dd/MM/yyyy")
			Catch
			End Try

			Try
				.ltrLastContactDate.Text = profile.offcier_expird_date.Value.AddDays(90).AddYears(543).ToString("dd/MM/yyyy")
			Catch
			End Try

			'############################################################################
			'Address on Id Card
			'############################################################################
			If Not String.IsNullOrEmpty(profile.officer_card_address_no) Then
				.ltrAddressCard1.Text = "เลขที่ " & profile.officer_card_address_no
			End If

			If Not String.IsNullOrEmpty(profile.officer_card_address_moo) Then
				If .ltrAddressCard1.Text.Length > 0 Then
					.ltrAddressCard1.Text &= " "
				End If
				.ltrAddressCard1.Text &= "หมู่ " & profile.officer_card_address_moo
			End If

			If Not String.IsNullOrEmpty(profile.officer_card_address_building) Then
				If .ltrAddressCard1.Text.Length > 0 Then
					.ltrAddressCard1.Text &= " "
				End If
				.ltrAddressCard1.Text &= "หมู่บ้าน/อาคาร " & profile.officer_card_address_building
			End If

			If Not String.IsNullOrEmpty(profile.officer_card_address_soi) Then
				If .ltrAddressCard1.Text.Length > 0 Then
					.ltrAddressCard1.Text &= " "
				End If
				.ltrAddressCard1.Text &= "ซอย " & profile.officer_card_address_soi
			End If

			If Not String.IsNullOrEmpty(profile.officer_card_address_street) Then
				If .ltrAddressCard1.Text.Length > 0 Then
					.ltrAddressCard1.Text &= " "
				End If
				.ltrAddressCard1.Text &= "ถนน " & profile.officer_card_address_street
			End If

			If Not String.IsNullOrEmpty(profile.officer_card_address_sub) Then
				If .ltrAddressCard1.Text.Length > 0 Then
					.ltrAddressCard1.Text &= " "
				End If
				.ltrAddressCard1.Text &= "ตำบล/แขวง " & profile.officer_card_address_sub
			End If

			If Not String.IsNullOrEmpty(profile.officer_card_address_district) Then
				If .ltrAddressCard1.Text.Length > 0 Then
					.ltrAddressCard1.Text &= " "
				End If
				.ltrAddressCard1.Text &= "อำเภอ/เขต " & profile.officer_card_address_district
			End If

			If Not String.IsNullOrEmpty(profile.officer_card_address_province) Then
				If .ltrAddressCard1.Text.Length > 0 Then
					.ltrAddressCard1.Text &= " "
				End If
				.ltrAddressCard1.Text &= "จังหวัด " & profile.officer_card_address_province
			End If

			If Not String.IsNullOrEmpty(profile.officer_card_address_postcode) Then
				If .ltrAddressCard1.Text.Length > 0 Then
					.ltrAddressCard1.Text &= " "
				End If
				.ltrAddressCard1.Text &= "รหัสไปรษณีย์ " & profile.officer_card_address_postcode
			End If
			'################################## Address on Id Card ##########################################

			'############################################################################
			'Address on mail
			'############################################################################
			If Not String.IsNullOrEmpty(profile.officer_mail_address_no) Then
				.ltrAddress1.Text = "เลขที่ " & profile.officer_mail_address_no
			End If

			If Not String.IsNullOrEmpty(profile.officer_mail_address_moo) Then
				If .ltrAddress1.Text.Length > 0 Then
					.ltrAddress1.Text &= " "
				End If
				.ltrAddress1.Text &= "หมู่ " & profile.officer_mail_address_moo
			End If

			If Not String.IsNullOrEmpty(profile.officer_mail_address_building) Then
				If .ltrAddress1.Text.Length > 0 Then
					.ltrAddress1.Text &= " "
				End If
				.ltrAddress1.Text &= "หมู่บ้าน/อาคาร " & profile.officer_mail_address_building
			End If

			If Not String.IsNullOrEmpty(profile.officer_mail_address_soi) Then
				If .ltrAddress1.Text.Length > 0 Then
					.ltrAddress1.Text &= " "
				End If
				.ltrAddress1.Text &= "ซอย " & profile.officer_mail_address_soi
			End If

			If Not String.IsNullOrEmpty(profile.officer_mail_address_street) Then
				If .ltrAddress1.Text.Length > 0 Then
					.ltrAddress1.Text &= " "
				End If
				.ltrAddress1.Text &= "ถนน " & profile.officer_mail_address_street
			End If

			If Not String.IsNullOrEmpty(profile.officer_mail_address_sub) Then
				If .ltrAddress1.Text.Length > 0 Then
					.ltrAddress1.Text &= " "
				End If
				.ltrAddress1.Text &= "ตำบล/แขวง " & profile.officer_mail_address_sub
			End If

			If Not String.IsNullOrEmpty(profile.officer_mail_address_district) Then
				If .ltrAddress1.Text.Length > 0 Then
					.ltrAddress1.Text &= " "
				End If
				.ltrAddress1.Text &= "อำเภอ/เขต " & profile.officer_mail_address_district
			End If

			If Not String.IsNullOrEmpty(profile.officer_mail_address_province) Then
				If .ltrAddress1.Text.Length > 0 Then
					.ltrAddress1.Text &= " "
				End If
				.ltrAddress1.Text &= "จังหวัด " & profile.officer_mail_address_province
			End If

			If Not String.IsNullOrEmpty(profile.officer_mail_address_postcode) Then
				If .ltrAddress1.Text.Length > 0 Then
					.ltrAddress1.Text &= " "
				End If
				.ltrAddress1.Text &= "รหัสไปรษณีย์ " & profile.officer_mail_address_postcode
			End If
			'################################## Address on Id Card ##########################################

			.ltrContactTel.Text = profile.officer_mail_phone
			.ltrEmail.Text = profile.officer_mail_email
			.ltrSender.Text = profile.officer_sender_name & " " & profile.officer_sender_surename

			'################################## Bank Account Info ##########################################
			.ltrBankName.Text = profile.bank_name
			.ltrBankAccName.Text = profile.officer_bank_account_name
			.ltrAccountNo.Text = profile.officer_bank_account_code
			.ltrBankBrach.Text = profile.officer_bank_branch

			Try
				.ltrLastModifyDate.Text = profile.upd_date.Value.AddYears(543).ToString("dd/MM/yyyy")
			Catch
			End Try

		End With
	End Sub

	Private Sub ucEditAddress1_AfterUpdate(ByVal officerId As String) Handles ucEditAddress1.AfterUpdate
		Server.Transfer("~/Profile.aspx")
	End Sub
End Class